package com.veer.shop.controller.admin;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.veer.shop.annotation.ApiControllerLog;
import com.veer.shop.annotation.ApiSecured;
import com.veer.shop.config.ApiUrlConfig;
import com.veer.shop.param.MaterialsParam;
import com.veer.shop.pojo.Material;
import com.veer.shop.pojo.ResponseData;
import com.veer.shop.service.impl.admin.MaterialsServiceImpl;

/**
 * 系统素材管理  控制器
 * 
 * @author WangBin
 * 2020年10月06日-下午5:52:04
 */
@RestController
public class MaterialsController {
	
	@Autowired
	private MaterialsServiceImpl materialsServiceImpl;
	
	/**
	 * 获取素材列表
	 */
	@ApiSecured
	@ApiControllerLog(description = "获取素材列表")
	@RequestMapping( path = ApiUrlConfig.API_MATERIALS_LIST_URL, method = RequestMethod.GET)
	public ResponseData<?> getList(@RequestBody(required = false) MaterialsParam materialsListParam, @RequestParam(name = "page_no", defaultValue = "1", required = false) int pageNo, @RequestParam(name = "page_size", defaultValue = "20", required = false)int pageSize)
	{
		return materialsServiceImpl.getList(materialsListParam, pageNo, pageSize);
	}
	
	/**
	 * 上传|修改素材
	 */
	@ApiSecured
	@ApiControllerLog(description = "上传|修改素材")
	@RequestMapping( path = ApiUrlConfig.API_MATERIAL_CATEGORY_UPDATE_URL, method = RequestMethod.POST)
	public ResponseData<?> update(@RequestBody Material material)
	{
		return materialsServiceImpl.update(material);
	}
	
	/**
	 * 删除素材
	 */
	@ApiSecured
	@ApiControllerLog(description = "删除素材")
	@RequestMapping( path = ApiUrlConfig.API_MATERIAL_CATEGORY_DELETE_URL, method = RequestMethod.POST)
	public ResponseData<?> delete(@RequestParam(name = "material_id", defaultValue = "") String materialId, @RequestParam(name = "file_deleted", defaultValue = "1") String fileDeleted)
	{
		return materialsServiceImpl.delete(materialId, Integer.parseInt(fileDeleted));
	}
	
	/**
	 * 素材详情
	 */
	@ApiSecured
	@ApiControllerLog(description = "素材详情")
	@RequestMapping( path = ApiUrlConfig.API_MATERIAL_CATEGORY_GET_URL, method = RequestMethod.GET)
	public ResponseData<?> get(@RequestParam(name = "material_id", defaultValue = "") int materialId)
	{
		return materialsServiceImpl.get(materialId);
	}
}
